package com.ruoyi.project.blog.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.blog.domain.BComment;
import com.ruoyi.project.blog.service.IBCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 评论Controller
 *
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/news/comment")
public class BCommentController extends BaseController {
    @Autowired
    private IBCommentService bCommentService;

    /**
     * 查询评论列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BComment bComment) {
        startPage();
        List<BComment> list = bCommentService.selectBCommentList(bComment);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @Log(title = "评论管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BComment bComment) {
        List<BComment> list = bCommentService.selectBCommentList(bComment);
        ExcelUtil<BComment> util = new ExcelUtil<BComment>(BComment.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bCommentService.selectBCommentById(id));
    }

    /**
     * 新增评论
     */
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BComment bComment) {
        return toAjax(bCommentService.insertBComment(bComment));
    }

    /**
     * 修改评论
     */
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BComment bComment) {
        return toAjax(bCommentService.updateBComment(bComment));
    }

    /**
     * 删除评论
     */
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bCommentService.deleteBCommentByIds(ids));
    }

    @RequestMapping(value = "/listForkeyWords", method = RequestMethod.GET)
    @ApiOperation(value = "评论管理", httpMethod = "GET", response = AjaxResult.class, notes = "评论列表")
    public TableDataInfo listForkeyWords(String keywords) {
        return getDataTable(bCommentService.listComment(keywords));
    }

}
